/* Wang Wen(Albert Wang) jawangwen@gmail.com */

#ifndef __RT_REFER_H__
#define __RT_REFER_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <assert.h>
#include "rt_debug.h"

#define REFER_INIT(exec_name) do {                  \
    RT_REFER_TRACE("[init_refer] %s", exec_name);   \
    assert(!refer_init(exec_name));                 \
} while (0)

#define REFER_FUNC(refer, func_name, file_name) do {                                    \
    RT_REFER_TRACE("[refer_func] func_name<%s>, file_name<%s>", func_name, file_name);  \
    assert(!refer_func((void **)&(refer), (func_name), (file_name)));                   \
} while (0)

#define SET_REFERS(refers) do {                                     \
    int refer_num = sizeof(refers) / sizeof(refers)[0];             \
    int refer_index;                                                \
    for (refer_index = 0; refer_index < refer_num; ++refer_index) { \
        refers[refer_index]();                                      \
    }                                                               \
} while (0)

typedef void (* refers) (void);

int refer_init (const char * exec_name);
int refer_func (void ** refer_ptr, const char * func_name, const char * file_name);

#ifdef __cplusplus
}
#endif

#endif /* __RT_REFER_H__ */

